﻿// See https://aka.ms/new-console-template for more information

using P4_BbookStore;

BookManager manager = new();

        int choice = -1;

        while (choice != 0)
        {
            Console.Clear();
            Console.WriteLine("图书管理系统");
            Console.WriteLine("1. 查看所有图书");
            Console.WriteLine("2. 查找图书");
            Console.WriteLine("3. 添加图书");
            Console.WriteLine("4. 删除图书");
            Console.WriteLine("5. 更新图书库存");
            Console.WriteLine("0. 退出系统");
            Console.Write("请选择操作：");

            string? input = Console.ReadLine();
            if (!int.TryParse(input, out choice))
            {
                Console.WriteLine("请输入有效数字！");
                Console.ReadKey();
                continue;
            }

            Console.WriteLine();
            switch (choice)
            {
                case 1:
                    manager.Print();
                    break;
                case 2:
                    Console.Write("请输入书名关键词：");
                    string keyword = Console.ReadLine();
                    manager.FindBook(keyword ?? "");
                    break;
                case 3:
                    Console.Write("书名：");
                    string title = Console.ReadLine();
                    Console.Write("作者：");
                    string author = Console.ReadLine();
                    Console.Write("库存数量：");
                    if (int.TryParse(Console.ReadLine(), out int stock))
                        manager.AddBook(title ?? "", author ?? "", stock);
                    else
                        Console.WriteLine("库存必须是数字！");
                    break;
                case 4:
                    Console.Write("请输入要删除的书名：");
                    string deleteTitle = Console.ReadLine();
                    manager.DeleteBook(deleteTitle ?? "");
                    break;
                case 5:
                    Console.Write("请输入要更新的书名：");
                    string updateTitle = Console.ReadLine();
                    Console.Write("新库存数量：");
                    if (int.TryParse(Console.ReadLine(), out int newStock))
                        manager.ModifyBook(updateTitle ?? "", newStock);
                    else
                        Console.WriteLine("库存必须是数字！");
                    break;
                case 0:
                    Console.WriteLine("再见！");
                    break;
                default:
                    Console.WriteLine("无效的选择！");
                    break;
            }

            Console.WriteLine("\n按任意键继续...");
            Console.ReadKey();
        }